package com.ktgj.service.task;

import com.ktgj.common.core.constant.CustomerConstants;
import com.ktgj.service.domain.OrderVipchannel;
import com.ktgj.service.domain.OrderViphall;
import com.ktgj.service.domain.OrderitemVipchannel;
import com.ktgj.service.domain.OrderitemViphall;
import com.ktgj.service.mapper.OrderVipchannelMapper;
import com.ktgj.service.mapper.OrderViphallMapper;
import com.ktgj.service.mapper.OrderitemVipchannelMapper;
import com.ktgj.service.mapper.OrderitemViphallMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class Scheduler {

    @Autowired
    private OrderViphallMapper orderViphallMapper;

    @Autowired
    private OrderitemViphallMapper orderitemViphallMapper;

    @Autowired
    private OrderVipchannelMapper orderVipchannelMapper;

    @Autowired
    private OrderitemVipchannelMapper orderitemVipchannelMapper;

    /**
     * 取消贵宾厅订单
     * @param
     * @return
     */
    @Scheduled(fixedDelay = 1000 * 60)
    public void cancelOrder() {
        List<OrderViphall> orderViphalls = orderViphallMapper.selectOrderViphall();
        for (OrderViphall orderViphall : orderViphalls) {
            orderViphall.setStatus(CustomerConstants.cancelPay.getValue());
            orderViphall.setPaymentStatus(CustomerConstants.cancelPay.getValue());
            orderViphallMapper.updateOrderViphall(orderViphall);
            OrderitemViphall orderitemViphall = new OrderitemViphall();
            orderitemViphall.setOrderviphallId(orderViphall.getJsjId());
            orderitemViphall.setStatus(CustomerConstants.unexecuted.getValue());
            orderitemViphallMapper.updateOrderitemViphallByStatus(orderitemViphall);
        }
    }

    /**
     * 取消VIP通道订单
     */
    @Scheduled(fixedDelay = 1000 * 60)
    public void cancelOrderVipChannel() {
        List<OrderVipchannel> ordervipchannel = orderVipchannelMapper.selectOrdervipchannel();
        for (OrderVipchannel orderVipchannel : ordervipchannel) {
            orderVipchannel.setStatus(CustomerConstants.cancelPay.getValue());
            orderVipchannel.setPaymentStatus(CustomerConstants.cancelPay.getValue());
            orderVipchannelMapper.updateOrderVipchannel(orderVipchannel);
            OrderitemVipchannel orderitemVipchannel = new OrderitemVipchannel();
            orderitemVipchannel.setOrdervipchannelId(orderVipchannel.getOrdervipchannelId());
            orderitemVipchannel.setStatus(CustomerConstants.unexecuted.getValue());
            orderitemVipchannelMapper.updateOrderitemVipchannelStatus(orderitemVipchannel);
        }
    }

    /**
     * 贵宾厅订单明细
     * @param
     * @return
     */
    @Scheduled(fixedDelay = 1000 * 60)
    public void selectOrderViphallByCustomerId() {
        List<OrderViphall> orderViphalls = orderViphallMapper.selectOrderViphall();
        for (OrderViphall orderViphall : orderViphalls) {
            orderViphall.setStatus(CustomerConstants.cancelPay.getValue());
            orderViphallMapper.updateOrderViphall(orderViphall);
        }
    }
}
